package com.local.order.service.impl;

import com.local.common.util.ResultUtil;
import com.local.order.mapper.OrderItemMapper;
import com.local.order.pojo.OrderItem;
import com.local.order.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class OrderItemServiceImpl implements OrderItemService {

    @Autowired
    private OrderItemMapper orderItemMapper;

    /**
     * 通过 orderId 查询订单商品明细
     * @param orderId
     * @return
     */
    @Override
    public List<OrderItem> selectByOrderId(Integer orderId) {
        return orderItemMapper.selectByOrderId(orderId);
    }


    /**
     * 通过 id 查询订单商品明细
     * @param orderItemId
     * @return
     */
    @Override
    public OrderItem selectById(Integer orderItemId) {
        return orderItemMapper.selectById(orderItemId);
    }


    /**
     * 批量插入数据
     * @param orderItemList
     * @return
     */
    @Override
    public ResultUtil<String> saveByList(List<OrderItem> orderItemList) {
        Integer result = orderItemMapper.saveByList(orderItemList);
        if (Objects.nonNull(result) && result > 0) {
            return new ResultUtil<>(200, "", "");
        } else {
            return new ResultUtil<>(201, "", "数据添加失败，请稍后再试");
        }
    }
}
